package com.guan.poi.core;

import com.guan.poi.core.face.Area;
import com.guan.poi.core.face.Styleable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
public class PoiRow extends Node implements Area, Styleable {
	private Integer row = 1;

	/** 样式 */
	private PoiStyle style;

	/** Column属性的全部定义 */
	private List<Cel> cels = new ArrayList<>();

	public PoiRow() {}

	public PoiRow(int row) {
		this.row = row;
	}

	public PoiRow(int row, String... values) {
		this(row);
		for (String value : values) {
			addCel(value);
		}
	}

	public PoiRow(int row, int cel, String... values) {
		this(row);
		for (String value : values) {
			addCel(cel, value);
		}
	}

	public Cel addCel(Cel cel) {
		cel.parent(this);
		cels.add(cel);
		return cel;
	}

	public Cel addCel(String value) {
		return addCel(new Cel(value));
	}

	public Cel addCel(int cel, String value) {
		return addCel(new Cel(value).setCel(cel));
	}

	public PoiRow addCels(String... values) {
		for (String value : values) {
			addCel(new Cel(value));
		}
		return this;
	}

	public PoiRow addCels(int cel, String... values) {
		for (String value : values) {
			addCel(cel, value);
		}
		return this;
	}


	@Getter
	@Accessors(chain = true)
	public static class Cel extends Node implements Styleable {
		@Setter
		private Integer cel = 1;

		/** 样式 */
		@Setter
		private PoiStyle style;

		/** cell的宽度 */
		@Setter
		private Float columnWidth;

		private final Object value;

		public Cel(String value) {
			this.value = value;
		}
	}
}
